package test;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;

import java.util.logging.Logger;
/**
 * Client 网络IO事件处理
 * @author xwalker
 *
 */
public class TimeClientHandler extends ChannelHandlerAdapter {
    private static final Logger logger=Logger.getLogger(TimeClientHandler.class.getName());
    private  ByteBuf firstMessage;
    public TimeClientHandler(){
        firstMessage=Unpooled.copiedBuffer("QUERY TIME ORDER".getBytes());
    }
    @Override
    public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
    	// TODO Auto-generated method stub
    	for (int i = 0; i < 1000; i++) {
        	ctx.writeAndFlush(firstMessage);
		}

        System.out.println("客户端active");
    }
    @Override
    public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
    	// TODO Auto-generated method stub
    }
    
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    	// TODO Auto-generated method stub
    	cause.printStackTrace();
    }
}